<?php

 /**
  * @package JooS
  * @subpackage PHPackager
  */

  require_once "JooS/Helper/Abstract.php";

  class JooS_PHPackager_Helper_Attach extends JooS_Helper_Abstract {
    /**
     * @param string $name
     * @param array $callback
     */
    public function __invoke($name, $callback) {
      require_once "JooS/PHPackager/Manager.php";
      
      require_once "JooS/Event/Event/Config/Commit.php";

      require_once "JooS/Loader.php";

      if (JooS_Loader::loadClass($name)) {
        $rc = new ReflectionClass($name);
        
        $Event = $rc->getMethod("getInstance")->invoke(null)
          ->attach($callback);

        JooS_Event_Event_Config_Commit::getInstance()
          ->setEvent($Event)
          ->notify();
      }
      else {
        require_once "JooS/PHPackager/Helper/Exception.php";
        
        throw new JooS_PHPackager_Helper_Exception("Class for '$name' event not found");
      }
    }
  }
